import java.util.Arrays;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class  Group {
    int a;
    static Group build(int a) {
            return new Group(a);
    }

    private Group(int a) {
        this.a = a;
    }
}

class NmeaInfo implements Cloneable {
    public String name = "name";
    public String name1 = "name1";

    public void clear() {
        name = "";
        name1 = "";
    }
    @Override
    public NmeaInfo clone() {
        try {
            return (NmeaInfo) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }
}

public class ParseNmea {


    public static void main(String[] args) {
        NmeaInfo nmeaInfo = new NmeaInfo();
        nmeaInfo.name = "fyj";
        nmeaInfo.name1="fyj1";
        NmeaInfo nmeaInfo1 = nmeaInfo.clone();
        nmeaInfo.clear();


        HashMap<String, String> map = new HashMap<>();
        map.put("1","adasd");
        map.put("1","adasd1");
        map.put("2","adasd2");
        map.put("3","adasd3");
        map.put("4","adasd4");

        map.forEach((k,v) -> System.out.println("key:" + k + " value:" +  v));


        String rma = "$GNRMC,000842.010,V,8960.0000,N,00000.0000,E,0.000,0.00,010110,,,N*51";

        int index = rma.indexOf(",");
        System.out.println("index:" + index + "  head:" + rma.substring(0,index));

        if (rma.contains("\r\n")) {

            System.out.println("contains winows lines");
        } else if (rma.contains("\n")) {
            System.out.println("contains unix lines");
        }
        StringBuilder builder = new StringBuilder();
        builder.setLength(0);

        //        match_obj = re.match("^\\d.*\\d$\", \"4hello_world4\")\n"
        String[] rmaArr = rma.split(",");
        if (rmaArr != null && rmaArr.length > 1) {
            String aa = rmaArr[0];
            String regex = "^\\$.*RMC$"; // 正则表达式，以RMC  结尾 ，以$开头
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(aa);
            boolean find = matcher.find();
            System.out.println("match:" + find + "  rmaArr[0]:" + aa);

            if (find) {
               if (rmaArr.length > 2) {
                    String status = rmaArr[2];
                    if ("V".equals(status)) {}

                   String flagLgt = rmaArr[3];
                   String latitudeDegreeStr = flagLgt.substring(0,2);
                   int latitudeDegreeInt = Integer.valueOf(latitudeDegreeStr);

                   String latitudeDegreeMMStr = flagLgt.substring(2);

                   float latitudeDegreeMM = Float.valueOf(latitudeDegreeMMStr) * 10000;
                   float latitudeDegreeMMF = (latitudeDegreeMM / 60)  / 10000;

                   float lgt = latitudeDegreeInt + latitudeDegreeMMF;
                   System.out.println("latitudeDegreeInt:" + latitudeDegreeInt + " lgtDegreeMMStr:" + latitudeDegreeMMStr + " lgtDegreeMM:" + latitudeDegreeMM + " lgtDegreeMMF:" + latitudeDegreeMMF);
                   System.out.println("latitude:" + lgt);


                   int longitude = Integer.valueOf(rmaArr[5].substring(0,2));
                   float logitudeMM = Float.valueOf(rmaArr[5].substring(3));
                   System.out.println("longitude:" + longitude + "logitudeMM:" + logitudeMM + " longitudeResult:" + (longitude + logitudeMM));
               }
            }
        }
    }
}
